/*
 * Copyright (c) 2020, 2023, 3044483124@qq.com All rights reserved.
 *
 */
package cn.itcast;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * <p>Project: JavaStudy - Book
 * <p>Powered by jiangbo On 2023-01-12
 * 15:08:16
 * <p>Created by IntelliJ IDEA
 *
 * @author jiangbo [3044483124@qq.com]
 * @version 1.0
 * @since 8/17
 */
public class Book {
    private int id;
    private String name;
    private String author;
    private double price;

    public Book() {

    }

    static List<Book> list = new ArrayList<>();

    public Book(int id, String name, String author, double price) {
        this.id = id;
        this.name = name;
        this.author = author;
        this.price = price;
//        getter setter….
    }

    public int getId() {
        return id;
    }

    public void steId(int id) {
        this.id = id;

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;

    }

    public String getAuthor() {
        return author;

    }

    public void setAuthor(String author) {
        this.author = author;

    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int i = 0;
        while (true) {
            i = list.size() + 1;
            System.out.printf("请输入第%d本书籍名称  作者  价格: ", i);
            String n = sc.next();
            String a = sc.next();
            double p = sc.nextDouble();
            Book bk = new Book(i, n, a, p);
            list.add(bk);
            if (list.size() == 10) {
                System.out.println("10 书籍输入完成。 进入程序查询");
                break;
            }
            System.out.println();

        }
        System.out.println();

        System.out.println("----------------------------------------");

        while(true)

        {
            System.out.print("请输入书籍名称(退出quit)：");
            String n = sc.nextLine();
            if ("quit".equalsIgnoreCase(n)) break;
            for (Book b : list) {
                if (b.getName().contains(n)) {
                    System.out.println(b);
                }
            }
            System.out.println();
        }


    }

    @Override
    public String toString() {
        return "Book{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", author='" + author + '\'' +
                ", price=" + price +
                '}';
    }
}


